<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Info extends MY_Controller
{

	public function __construct()
	{
		parent::__construct();
		$this->load->model('User_model');

	}

	//检查 agid 的是否存在
	public function check_agid(){
		$agid = $this->input->get('agid');
		//如果 agid 为空,说明 agid 参数存在,但无值,
		//如果为null 则说明无 agid 参数
		if (isset($agid) && $agid==='') {
			$error = array(
				"用户信息操作错误, 要修改的用户不存在 或 未选择用户类型!",
				"class:".$this->router->directory.$this->router->class.",method:".$this->router->method.",userid:{$agid},usertype:{$this->input->get('agusertype')}"
			);
			alert_err($error, $this->reffer);
		}

	}

	public function index()
	{
// 		$this->check_agid();
		$loginFlag = FALSE; // 用户判断是否修改登陆账号
		$data_body = array(); // 初始化

		$that_userid = _get_key_val($this->input->get('agid'), true);
		$that_usertype = $this->input->get('agusertype');

		if ( ! $that_userid || ! $that_usertype )
		{
			$that_userid = $this->thatUser['id'];
			$that_usertype = $this->thatUser['usertype'];
			$loginFlag = TRUE; // 判断是修改登陆账户
		}
		
		// 用户链接
		if ($loginFlag) {
			extract($this->m_user_url($that_userid));
		} else {
			extract($this->m_sub_user_url($that_userid, $that_usertype));
		}
		//$infoUrl = (TRUE == $loginFlag) ? '/m/info/' : '/m/info?agid=' . _get_key_val($that_userid) . '&agusertype=' . $that_usertype;
		//$picUrl = (TRUE == $loginFlag) ? '/m/info/personalPic' : '/m/info/personalPic?agid=' . _get_key_val($that_userid) . '&agusertype=' . $that_usertype;
		//$avatarUrl = (TRUE == $loginFlag) ? '/m/photo/' : '/m/photo?agid=' . _get_key_val($that_userid) . '&agusertype=' . $that_usertype;
		//$workUrl = (TRUE == $loginFlag) ? '/m/works' : '/m/works?agid=' . _get_key_val($that_userid);
		if ( in_array($that_usertype, array(
			2,
			3
		)) )
		{
			// 机构或者企业
			$completeUrl = '/m/info/';
		} else
		{
			$completeUrl = $picUrl;
		}
		// is_post()
		if ( $this->input->is_post() )
		{
			if ( $that_usertype == 1 )
			{
				// 模特
				list ($config, $data, $data_detail, $data_memo, $data_body) = $this->m_model_config();
			} 
			else if ( in_array($that_usertype, array(4,5,6)) )
			{
				// 摄影师或者化妆师
				list ($config, $data, $data_detail, $data_memo) = $this->m_photo_config($that_usertype);
			} 
			else if ( $that_usertype == 2 || ($that_usertype == 3) )
			{
				// 机构或者企业
				list ($config, $data, $data_detail, $data_memo) = $this->m_ins_config();
			}
			
			//用户信息
			$userModel = $this->User_model->get_by_id($that_userid);
			//状态值
			$flag = 0;
			if (!$userModel['qq'])
			    $flag = 1;
			
			// $this->form_validation->set_rules($config);
			// if ($this->form_validation->run() === TRUE) {
			// 保存数据库
			$res = $this->User_model->update_info_by_id($that_userid, $data, $data_detail, $data_memo, $data_body);
// 			echo $this->User_model->db->last_query();die;
// 			die;
// 			alert('保存成功', $completeUrl);
			if ( in_array($that_usertype, array(2,3)) )
			{
				$completeUrl .= '?res='.$res;
			}
			
			//完善资料魔币奖赏规则
			if ($userModel)
			{
			    if (!$userModel['insid'])
			    {
			        $this->load->model('Magic_coins_model');
			        $magicCoinsModel = $this->Magic_coins_model->get_by_where(array('userid'=>$that_userid,'origin'=>2));
			        if (!$magicCoinsModel)
			        {
			            //用户完善资料获取200魔币
			            $this->load->service('magic_service');
			            $this->magic_service->recordMagicCoins($that_userid,200,2);
			        }
			    }
			    else
			    {
			        if ($flag)
			        {
			            //机构添加艺人并完善资料可获得300魔币
			            $this->load->service('magic_service');
			            $this->magic_service->recordMagicCoins($userModel['insid'],300,2);
			        }
			    }
			}
			
			alert('保存成功', $completeUrl);
// 			redirect($completeUrl);
			// }
		} // -is_post()
		  
		// begin:右侧-推荐用户
		$right_usertype = 1;
		$right_sex = 1;
		if ( $this->loginUsertype == 1 )
			$right_usertype = 2;
		if ( $this->loginUser['sex'] == 1 )
			$right_sex = 2;
		$arrWhere = array(
			'usertype' => $right_usertype,
			'status' => 1,
			'userlevel' => 1,
			'sex' => $right_sex
		);
		$feild = 'user.id,nickname,userlogo,company';
		$this->load->model('Recommend_model');
		$rightlist = $this->Recommend_model->get_user_list($arrWhere, $feild, 10);
		// end:右侧-推荐用户
		
		$o = $this->User_model->get_info_by_id($that_userid);
		
		//获取认证状态
		$this->load->model('Cert_model');
		$cert = $this->Cert_model->get_by_where("userid=".$that_userid,'status');
		$o["cert_status"] = $cert["status"];
		
		// 风格
		$this->load->model('Style_model');
		$oSysModelstyle = $this->Style_model->getShowStyle();
		$oSysType = array();
		if ( in_array($this->loginUsertype, array(1,2,3,6)) )
		{
		    if ($this->loginUsertype == 3)
		    {
		        $oSysType = $this->config->item('type');
		        $oSysType = $oSysType[$this->loginUsertype];
		    }
		    else 
		    {
		        $oSysType = _get_config('type',true);
		        $oSysType = $oSysType[$this->loginUsertype];
		    }
		}
		$this->load->model('Userbody_model');
		$oBody = $this->Userbody_model->get_by_id($that_userid);
		//模特地域分类
		$areaType = _get_config('area_type');
		$result = array(
			'o' => $o,
			'rightlist' => $rightlist,
			'oSysModelstyle' => $oSysModelstyle,
			'oSysType' => $oSysType,
			'oBody' => $oBody,
			'oThatID' => $that_userid,
			'usertype' => $that_usertype,
			'infoUrl' => $infoUrl,
			'picUrl' => $picUrl,
			'hasAvatar' => $loginFlag, // 是否需要头像设置
			'avatarUrl' => $avatarUrl,
			'workUrl' => $workUrl,
			'areaType' => $areaType
		); // 设置头像的链接
		
		if (in_array($that_usertype, array(1,4,5,6)))
		{
			$user_role = _get_config('user_role');
			$roleArr = array();
			if ($that_usertype == 1)
			{
				$roleArr = $user_role[11];
			}
			elseif ($that_usertype == 4)
			{
				$roleArr = $user_role[1];
			}
			elseif ($that_usertype == 5)
			{
				$roleArr = $user_role[2];
			}
			elseif ($that_usertype == 6 && $o['type'])
			{
				$roleArr = $user_role[$o['type']];
			}
			$result['roleArr'] = $roleArr;
		}

		$view = 'm/info';
		
		if ( $that_usertype == 2 )
		{
			// 机构或者企业
			$view = 'm/info_ins';
		} 
		else if ( 3 == $that_usertype )
		{
			$view = 'm/info_com';
		}
		
		$this->load->view($view, $result);
	}

	/**
	 * 模特
	 *
	 * @return type
	 */
	private function m_model_config()
	{
		// 验证规则 -- required必填项
		$config = array(
			array(
				'field' => 'height',
				'label' => '身高',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'weight',
				'label' => '体重',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'bust',
				'label' => '三围',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'waist',
				'label' => '三围',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'hips',
				'label' => '三围',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'shoes',
				'label' => '鞋码',
				'rules' => 'trim|required'
			)
		);
		if ( ! $this->thatUser['nickname'] )
		{
			$config[] = array(
				'field' => 'nickname',
				'label' => '昵称',
				'rules' => 'trim|required'
			);
		}
		// -验证规则
		
		// $bust=$waist=$hips=0;
		// $arrBWH = explode('-', $this->input->post('BWH')) ;
		// if(count($arrBWH)>=1)
		// $bust = $arrBWH[0];
		// if(count($arrBWH)>=2)
		// $waist = $arrBWH[1];
		// if(count($arrBWH)>=3)
		// $hips = $arrBWH[2];
		
		$style = '';
		if ( is_array($this->input->post('style')) )
		{
			$style = implode(',', $this->input->post('style'));
		}
		
		//模特分类
		$role = '';
		$roleArr = $this->input->post('role');
		if (is_array($roleArr))
		{
			$roleArr = array_filter($roleArr);
			$role = implode(',', $roleArr);
		}
		if ($this->input->post('write_role'))
		{
			if ($role)
			{
				$role .= ',';
			}
			$role .= $this->input->post('write_role');
		}
		
		$data = array(
			// 基本资料
			'realname' => $this->input->post('realname'),
			'sex' => $this->input->post('sex'),
			'city' => $this->input->post('city'),
			'mobile' => $this->input->post('mobile'),
			'payeename' => $this->input->post('payee_name'),
			'payeeaccount' => $this->input->post('payee_account'),
			'area' => $this->input->post('area'),
			'qq' => $this->input->post('qq'),
		);
		
		$data_detail = array(
			// 消息资料
			'height' => $this->input->post('height'),
			'weight' => $this->input->post('weight'),
			'bust' => $this->input->post('bust'),
			'waist' => $this->input->post('waist'),
			'hips' => $this->input->post('hips'),
			'shoes' => (int) $this->input->post('shoes'),
			'cup' => strtoupper($this->input->post('cup')), // 大写，罩杯
			'style' => $style,
			'province_id' => (int) $this->input->post('province_id'),
			'city_id' => (int) $this->input->post('city_id'),
			'role' => $role
		);
		$data_memo = array(
			// 图片设置
			'brand' => $this->input->post('introduction'), // 个人说明
			                                               // 'brandtype'=>$this->input->post('brandtype'),
			                                               // 'awards'=>$this->input->post('awards'),
			'fee' => $this->input->post('introduction_w'), // 工作简介
			                                               // 'servicetime'=>$this->input->post('servicetime'),
			'takenote' => $this->input->post('takenote'),
			'planeshot' => $this->input->post('planeshot'),
			'tactivity' => $this->input->post('tactivity'),
			'telead' => $this->input->post('telead'),
			'magazine' => $this->input->post('magazine'),
			'bgimg' => $this->input->post('bgimg')
		);
		
		$data_memo['brand'] = str_replace('fr_ameWORK', 'FRAMEWORK', $data_memo['brand']);
		$data_memo['brand'] = str_replace('fr_amework', 'framework', $data_memo['brand']);
		$data_memo['fee'] = str_replace('fr_ameWORK', 'FRAMEWORK', $data_memo['fee']);
		$data_memo['fee'] = str_replace('fr_amework', 'framework', $data_memo['fee']);
		
		$data_body = array(
			// 身体尺寸设置
			'collarf' => (int) $this->input->post('bd_collarf'), // 领围
			'shoulderg' => (int) $this->input->post('bd_shoulderg'), // 肩宽
			'sleeveh' => (int) $this->input->post('bd_sleeveh'), // 臂长
			'sleevefull' => (int) $this->input->post('bd_sleevefull'), // 修长
			'outseam' => (int) $this->input->post('bd_outseam'), // 外侧裤长
			'inseamj' => (int) $this->input->post('bd_inseamj'), // 内测裤长
			'hatk' => (int) $this->input->post('bd_hatk'), // 头围
			'wristl' => (int) $this->input->post('bd_wristl'), // 腕围
			'thighm' => (int) $this->input->post('bd_thighm'), // 大腿围
			'calfn' => (int) $this->input->post('bd_calfn'), // 小腿围
			'hair' => $this->input->post('bd_hair'), // 头发
			'eye' => $this->input->post('bd_eye')
		); // 眼睛

		
		if ( $this->input->post('nickname') )
			$data['nickname'] = $this->input->post('nickname');
		
		return array(
			$config,
			$data,
			$data_detail,
			$data_memo,
			$data_body
		);
	}

	private function m_photo_config($usertype)
	{
		// 验证规则 required必填项
		$config = array(
			array(
				'field' => 'sex',
				'label' => '性别',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'realname',
				'label' => '真实姓名',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'mobile',
				'label' => '手机',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'city',
				'label' => '城市',
				'rules' => 'trim|required'
			)
		);
		if ( ! $this->thatUser['nickname'] )
			$config[] = array(
				'field' => 'nickname',
				'label' => '艺名',
				'rules' => 'trim|required'
			);
			// -验证规则
		
		$data = array(
			'realname' => $this->input->post('realname'),
			'sex' => $this->input->post('sex'),
			'city' => $this->input->post('city'),
			'mobile' => $this->input->post('mobile'),
			'qq' => $this->input->post('qq'),
			'wechat' => $this->input->post('wechat')
		);
		if ($this->input->post('showimg'))
		{
			$data['showimg'] = $this->input->post('showimg');
		}
		if ($this->input->post('showimg2'))
		{
			$data['showimg2'] = $this->input->post('showimg2');
		}
		
		//艺人分类
		$role = '';
		$roleArr = $this->input->post('role');
		if (is_array($roleArr))
		{
			$roleArr = array_filter($roleArr);
			$role = implode(',', $roleArr);
		}
		if ($this->input->post('write_role'))
		{
			if ($role)
			{
				$role .= ',';
			}
			$role .= $this->input->post('write_role');
		}
		
		
		$data_detail = array(
			'province_id' => (int) $this->input->post('province_id'),
			'city_id' => (int) $this->input->post('city_id'),
			'role' => $role
		);
		//艺人类型
		if ($usertype == 6)
		{
			$data_detail['type'] = $this->input->post('type');
		}
		$data_memo = array(
			'brand' => $this->input->post('introduction'),
			'brandtype' => $this->input->post('brandtype'),
			'memo' => $this->input->post('memo'),
			'fee' => $this->input->post('introduction_w'),
			'servicetime' => $this->input->post('servicetime'),
			'takenote' => $this->input->post('takenote'),
		);
		
		$data_memo['brand'] = str_replace('fr_ameWORK', 'FRAMEWORK', $data_memo['brand']);
		$data_memo['brand'] = str_replace('fr_amework', 'framework', $data_memo['brand']);
		$data_memo['fee'] = str_replace('fr_ameWORK', 'FRAMEWORK', $data_memo['fee']);
		$data_memo['fee'] = str_replace('fr_amework', 'framework', $data_memo['fee']);
		
		if ($this->input->post('bgimg'))
		{
			$data_memo['bgimg'] = $this->input->post('bgimg');
		}
		// 'video'=>$this->input->post('video'),
		
		if ( $this->input->post('nickname') )
			$data['nickname'] = $this->input->post('nickname');
		
		return array(
			$config,
			$data,
			$data_detail,
			$data_memo
		);
	}

	private function m_ins_config()
	{
		// 验证规则
		$config = array(
			// 联系人
			array(
				'field' => 'realname',
				'label' => '联系人姓名',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'mobile',
				'label' => '管理员手机',
				'rules' => 'trim|required'
			),
// 			array(
// 				'field' => 'email',
// 				'label' => '管理员邮箱',
// 				'rules' => 'trim|required'
// 			),
// 			array(
// 				'field' => 'wechat',
// 				'label' => '管理员微信',
// 				'rules' => 'trim|required'
// 			),
			array(
				'field' => 'memo',
				'label' => '公司简介',
				'rules' => 'trim|required'
			),
			// 机构信息
			array(
				'field' => 'nickname',
				'label' => '全称',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'com_short',
				'label' => '简称',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'com_phone',
				'label' => '联系电话',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'prov',
				'label' => '所在地区',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'com_email',
				'label' => '邮箱',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'type[]',
				'label' => '类型',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'showimg',
				'label' => 'logo图',
				'rules' => 'trim|required'
			),
			array(
				'field' => 'bgimg',
				'label' => '主页背景图',
				'rules' => 'trim|required'
			)
		);
		
		if ( ! $this->thatUser['nickname'] )
		{
			$config[] = array(
				'field' => 'nickname',
				'label' => '名称',
				'rules' => 'trim|required'
			);
		}
		// -验证规则
		
		$type = '';
		if ( is_array($this->input->post('type')) )
		{
			$type = implode(',', $this->input->post('type'));
		}
		
		$data = array(
			// 'userlogo'=>$this->input->post('userlogo'),
			'showimg' => $this->input->post('showimg'),
			'realname' => $this->input->post('realname'),
			'sex' => $this->input->post('sex'),
			'city' => $this->input->post('city'),
			'qq' => $this->input->post('qq'),
			'wechat' => $this->input->post('wechat'),
			'email' => $this->input->post('email')
		);
		
		$data_detail = array(
			'type' => $type,
			'com_short' => $this->input->post('com_short'),
			'website' => $this->input->post('com_website'),
			'com_email' => $this->input->post('com_email'),
			'com_phone' => $this->input->post('com_phone'),
			'com_prov' => $this->input->post('prov'),
			'com_city' => $this->input->post('city'),
			'com_dist' => $this->input->post('dist'),
		);
		$data_detail['website'] = str_replace('fr_amework', 'framework', $data_detail['website']);
		$data_memo = array(
			'memo' => $this->input->post('memo'),
			'bgimg' => $this->input->post('bgimg')
		);
		$data_memo['memo'] = str_replace('fr_ameWORK', 'FRAMEWORK', $data_memo['memo']);
		$data_memo['memo'] = str_replace('fr_amework', 'framework', $data_memo['memo']);
		
		$data['nickname'] = ($this->input->post('nickname')) ? $this->input->post('nickname') : $this->thatUser['nickname'];
		
		return array(
			$config,
			$data,
			$data_detail,
			$data_memo
		);
	}
	
	// 机构增加新人
	public function add()
	{
		$insid = $this->loginID;
		$usertype = $this->input->get('usertype');
		if ( ! in_array($usertype, array(
			1,
			4,
			5
		)) )
		{
			alert_err(array('用户类型错误, 请返回重新添加!'),$this->reffer);
			//echo 'error';
			//exit();
		}
		
		$id = $this->User_model->add_user_by_ins($insid, $usertype);
		
		// 新建默认相册
		if ( ! empty($id) && $id )
		{
			$this->load->model('Album_model');
			$this->Album_model->addDefaultAlbum($id, $insid);
			
			redirect(base_url('/m/info?agid=' . _get_key_val($id) . '&agusertype=' . $usertype));
		} else
		{
			redirect(base_url('/m/model'));
		}
	}

	/**
	 * 设置身体
	 * 废弃于2015-11-05
	 */
	public function setbody()
	{
		if ( $this->input->is_post() )
		{
			$id = $this->input->post('id');
			$userid = _get_key_val($id, true);
			$usertype = $this->input->post('t');
			
			if ( $userid )
			{
				$data_detail = array(
					'height' => (int) $this->input->post('bd_height'),
					'bust' => (int) $this->input->post('bd_bust'),
					'waist' => (int) $this->input->post('bd_waist'),
					'hips' => (int) $this->input->post('bd_hips'),
					'shoes' => (int) $this->input->post('bd_shoes')
				);
				$this->load->model('Userdetail_model');
				$this->Userdetail_model->update_by_where(array(
					'userid' => $userid
				), $data_detail);
				
				$data_body = array(
					'userid' => $userid,
					'hipd' => (int) $this->input->post('bd_hipd'),
					'hipe' => (int) $this->input->post('bd_hipe'),
					'collarf' => (int) $this->input->post('bd_collarf'), // 领围
					'shoulderg' => (int) $this->input->post('bd_shoulderg'), // 肩宽
					'sleeveh' => (int) $this->input->post('bd_sleeveh'), // 臂长
					'sleevefull' => (int) $this->input->post('bd_sleevefull'), // 修长
					'outseam' => (int) $this->input->post('bd_outseam'), // 外侧裤长
					'inseamj' => (int) $this->input->post('bd_inseamj'), // 内测裤长
					'hatk' => (int) $this->input->post('bd_hatk'), // 头围
					'wristl' => (int) $this->input->post('bd_wristl'), // 腕围
					'thighm' => (int) $this->input->post('bd_thighm'), // 大腿围
					'calfn' => (int) $this->input->post('bd_calfn'), // 小腿围
					'hair' => $this->input->post('bd_hair'), // 头发
					'eye' => $this->input->post('bd_eye')
				); // 眼睛

				
				$this->load->model('Userbody_model');
				$this->Userbody_model->insert($data_body);
			}
			
			if ( $userid != $this->thatUser['id'] )
				redirect('/m/info?agid=' . $id . '&agusertype=' . $usertype);
			else
				redirect('/m/info');
		}
	}
	
	// 保存图片
	public function personalPic()
	{
		$this->check_agid();
		$loginFlag = FALSE; // 用户判断是否是修改当前登陆账户

		// 机构中的个人信息
		$that_userid = _get_key_val($this->input->get('agid'), true);
		$that_usertype = $this->input->get('agusertype');
		
		if ( ! $that_userid || ! $that_usertype )
		{
			// 登陆用户
			$that_userid = $this->thatUser['id'];
			$that_usertype = $this->thatUser['usertype'];
			$loginFlag = TRUE; // 登陆用户标志
		}

		// 右侧信息 --- 热门推荐
		$right_usertype = 1;
		$right_sex = 1;
		if ( $this->loginUsertype == 1 )
		{
			$right_usertype = 2;
		}
		if ( $this->loginUser['sex'] == 1 )
		{
			$right_sex = 2;
		}
		
		$arrWhere = array(
			'usertype' => $right_usertype,
			'status' => 1,
			'userlevel' => 1,
			'sex' => $right_sex
		);
		$feild = 'user.id,nickname,userlogo,company';
		$this->load->model('Recommend_model');
		$rightlist = $this->Recommend_model->get_user_list($arrWhere, $feild, 10);
		
		// 链接
		if ( TRUE == $loginFlag ) {
			extract($this->m_user_url($that_userid));
		} else {
			extract($this->m_sub_user_url($that_userid, $that_usertype));
		}
		// 保存信息
		if ( $this->input->is_post() )
		{
			$picOne = $this->input->post('showimg');
			$picTwo = $this->input->post('showimg2');
			$video = $this->input->post('video');
			$upload_video = $this->input->post('upload_video');
			$bgImg = $this->input->post('bgimg');
			$recentPhoto = $this->input->post('recent_photo');
			
			if ($video)
			    $video = str_replace('pla_yer', 'player', $video);
			$video = $video?$video:$upload_video;
			
			// 形象照片
			$user = array(
				'showimg' => $picOne,
				'showimg2' => $picTwo
			);
			
			// 主页背景图，视频
			$user_memo = array(
				'bgimg' => $bgImg,
				'video' => $video,
				'recent_photo' => $recentPhoto
			);
			
			// 模特卡
			if ( 1 == $that_usertype )
			{
				$card = $this->input->post('card'); // 模特卡
				$user_memo['card'] = $card;
			}
			
			// 更新信息
			$this->User_model->update_info_by_id($that_userid, $user, array(), $user_memo);
			// 提示信息，并跳转
// 			redirect($avatarUrl);
// 			msg('已保存！', $avatarUrl, 2, 2000);
			alert('已保存', $avatarUrl);
		}

		// 个人信息
		$o = $this->User_model->get_info_by_id($that_userid);

		$data = array(
			'o' => $o,
			'rightlist' => $rightlist,
			'usertype' => $that_usertype,
			'infoUrl' => $infoUrl,
			'picUrl' => $picUrl,
			'hasAvatar' => $loginFlag,
			'avatarUrl' => isset($avatarUrl) ? $avatarUrl : '',
			'workUrl' => $workUrl
		);
		
		$this->load->view('/m/info2', $data);
	}
	
	//ajax获取分类
	public function getrole()
	{
		$res = array('code'=>0,'data'=>array());
		$roles = _get_config('user_role');
		$type = $this->input->post('type');
		$roleArr = $roles[$type];
		if($roleArr)
		{
			$res['code'] = 200;
			$res['data'] = $roleArr;
		}
		$this->view->json($res);
		exit;
	}
	
}